/*
 * @Author: Mainul Islam
 */

package edu.uta.cse.randomgraph.util;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

import edu.uta.cse.randomgraph.graph.property.Node;


public class MyDrawUtil {

	private static int margin = 10;
	private static int minDistanceBetweenPoint = 4;
	
	protected static boolean isSamePoint(int x1, int y1, int x2, int y2) {
		if( ((x1 - x2) * (x1 - x2) + (x1 - x2) * (x1 - x2)) <= minDistanceBetweenPoint)
			return true;
		return false;
	}

	public static void generateCoordinatesForNodes(int maxWidth, int maxHeight, Node nodes[], int numNodes) {
		int width = maxWidth - (margin * 2);
		int height = maxHeight - (margin * 2);
		Node n = new Node();  
			
		Random randX = new Random();
		Random randY = new Random();
			
		for (int i=0; i<numNodes; i++)	{
			n.X = randX.nextInt(width) + margin;
			n.Y = randY.nextInt(height) + margin;
				
			boolean duplicate = false;
			for(int j=0; j<i; j++) {
				if(n.X == nodes[j].X && n.Y == nodes[j].Y) {
				//if( isSamePoint(n.X, n.Y, nodes[j].X, nodes[j].Y) ) {
					duplicate = true;
						break;
				}
			}
				
			if(duplicate) {
				i--;
			}
			else {
				nodes[i].X = n.X;
				nodes[i].Y = n.Y;
			}
		}
		return;
	}
	
	public static void drawNode(int X, int Y, int diam, Color c, Graphics g) {
		g.setColor(c);
		g.fillOval(X, Y, diam, diam);
	}

	public static void drawNodeWithBorder(int X, int Y, int diam, Color c, Graphics g) {
		g.setColor(c);
		g.fillOval(X, Y, diam, diam);
		g.setColor(Color.BLACK);
		g.drawOval(X, Y, diam, diam);
	}

	public static void drawEdge(Node u, Node v, int rad, Color c, Graphics g) {
		g.setColor(c);
		g.drawLine(u.X+rad, u.Y+rad, v.X+rad, v.Y+rad);
	}
	
	public static Color assignColor(int n) {
		if(n == 0)
			return Color.DARK_GRAY;
		else if(n%9 == 1)
			return Color.LIGHT_GRAY;
		else if(n%9 == 2)
			return Color.GREEN;
		else if(n%9 == 3)
			return Color.RED;
		else if(n%9 == 4)
			return Color.BLUE;
		else if(n%9 == 5)
			return Color.YELLOW;
		else if(n%9 == 6)
			return Color.MAGENTA;
		else if(n%9 == 7)
			return Color.ORANGE;
		else if(n%9 == 8)
			return Color.CYAN;
		else // if(n%9 == 0)
			return Color.PINK;
	}

}
